#ifndef PACKET_H
#define PACKET_H

#include <time.h>
#include <QtCore/Q_INT32>
#include "utilities/utilities.h"
#include "utilities/DataAllocator.h"
#include "utilities/MemPool.h"
#include <windows.h>

class RawPacket
{
private:
	int mLength;
	int mCapLength;
	u_char *mData;
	timeval mTStamp;
	quint64 mNo;

	static DataAllocator m_Allocator;
	static SynMemPool m_Pool;
public:
	~RawPacket(void);

	void getArrvalTime (tm *t) const;
	timeval getTStamp() const {return mTStamp;}
	int getLength() const {return mLength;}
	int getCapLength() const {return mCapLength;}
	const u_char* getData() const {return mData;}
	bool isValid() const {return mLength == mCapLength;}
	qint64 getNo() const {return mNo;}
	void setNo(qint64 no) {this->mNo = no;}

	int serialize(unsigned char* buffer);

	void* operator new (size_t size) {
		return HeapAlloc(m_Heap,0,size);
		//return m_Pool.malloc();
	}

	void operator delete(void* p) {
		HeapFree(m_Heap,0,p);
		//m_Pool.free(p);
		//m_Allocator.free(mData,mCapLength);
	}

	RawPacket* clone();

	static const int PacketHeaderLength = 16;

private:
	static HANDLE m_Heap;

	static HANDLE mHeapForMicroAlloc;
	static HANDLE mHeapForLargeAlloc;

	RawPacket(const u_char *data,int len,u_int caplen,timeval ts);
	RawPacket(const RawPacket& obj);
	const RawPacket& operator = (const RawPacket& obj);
	friend class FrameCapturer;
};

#endif